/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package firezenk.logic;

import firezenk.gui.MainWindow;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import javax.swing.JProgressBar;

/**
 *
 * @author firezenk
 */
public class MainWindowLogic implements ActionListener, PropertyChangeListener {
    private MainWindow mw;
    private Downloader dl;
    private JProgressBar pb;

    public MainWindowLogic() {
        mw = new MainWindow();
        mw.setVisible(true);
        pb= mw.getBarraCarga();
        dl = new Downloader();
        dl.addPropertyChangeListener(this);
        dl.execute();
    }

    public void actionPerformed(ActionEvent e) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void propertyChange(PropertyChangeEvent evt) {
        if (evt.getPropertyName().equals("progress")) {
            int progress = (Integer) evt.getNewValue();
            pb.setValue(progress);
            if (progress == 100)
                pb.setValue(0);
            else if(progress == 10)
                mw.setLog(dl.getLog());
        }
    }

}
